package com.ruoyi.frame.util;

import cn.hutool.core.date.DatePattern;

import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * id 工具类
 *
 * @author zengXiangJiang
 * @version 1.0.0
 */
public class IdUtils {
    private static IdGenerator idGenerator = new IdGenerator();

    private static AtomicInteger seq = new AtomicInteger();

    /**
     * 获取雪花id
     * @return 18位id
     */
    public static Long getSnowflakeId() {
        return idGenerator.snowflakeId();
    }

    public static String getSnowflakeIdStr() {
        return String.valueOf(getSnowflakeId());
    }

    /**
     * 封装JDK自带的UUID, 通过Random数字生成, 中间无-分割.
     */
    public static String uuid() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }

    /**
     * 获取业务流水号
     */
    public static String getRpid(String hostId) {
//        String hostId = "HG";
        int incrementAndGet = seq.incrementAndGet();
        return String.format("%s%s%04d", hostId, DatePattern.PURE_DATETIME_PATTERN, incrementAndGet);
    }

}
